package com.cherry.ssm.client.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cherry.ssm.client.service.ClientService;


@Controller
public class ClientController{
	
	private static final Logger log = LoggerFactory.getLogger(ClientController.class);
	
	
	@Autowired
	private ClientService clientService;
	
	
	/**
	 * 通过HttpServletRequest获取请求源头的真实ip
	 * 通过真实ip在数据库中判断是否有接入权限
	 * 如果有,则将真实ip加密返回给客户端
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "/authentication")
	public HttpEntity authentication(HttpServletRequest request, HttpSession session){
		return this.clientService.authentication(request, session);
	}
	
	
	/**
	 * 从客户端,请求服务端登陆页面<通过/authentication接口返回的加密后的真实ip,解密后在数据库中判断是否有接入权限>
	 * 成功则跳转登陆页,失败跳转非法登陆
	 * @param client_url   客户端被拦截的请求
	 * @param intercept_url   完成登陆后重新定向到客户端的接口
	 * @param str   判断有接入权限后返回的标识</authentication接口返回的加密后的真实ip>
	 * @return
	 */
	@RequestMapping(value = "/loginpage")
	public String loginpage(String client_url, String intercept_url, String str, HttpServletRequest request, HttpSession session){
		return this.clientService.loginpage(client_url, intercept_url, str, request, session);
	}
	
	
	
	
	/**
	 * 从服务端,请求服务端登陆页面
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/inloginpage")
	public String inloginpage(HttpServletRequest request){
		log.info("进入登陆页");
		return "login/login";
	}
	
	
	/**
	 * 当前客户端非法请求
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/unlawful")
	public String unlawful(){
		log.error("当前客户端非法请求");
		return "login/error_unlawful";
	}
	
    
	/**
	 * 客户端请求有效期设置失败
	 * @return
	 */
	@RequestMapping(value = "/settingfalse")
	public String settingFalse(){
		log.error("当前客户端请求有效期设置失败");
		return "login/error_settingfalse";
	}
	
	
	/**
	 * SSO数据库中客户端ip请求配置有重复数据
	 * @return
	 */
	@RequestMapping(value = "/clientPrompt")
	public String clientPrompt(){
		log.error("SSO数据库中客户端ip请求配置有重复数据");
		return "login/client_prompt";
	}
	
	/**
	 * SSO数据库中未获取到客户端ip对应的请求配置
	 * @return
	 */
	@RequestMapping(value = "/notSettingip")
	public String notSettingip(){
		log.error("SSO数据库中未获取到客户端ip对应的请求配置");
		return "login/notSetting_ip";
	}
	
	/**
	 * 当前客户端请求超时
	 * @return
	 */
	@RequestMapping(value = "/requestOvertime")
	public String requestOvertime(){
		log.error("当前客户端请求超时");
		return "login/request_overtime";
	}
	
	
}
